﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Model;

namespace LaKuaShop_TestDemo.Page
{
    /// <summary>
    /// LoginPage.xaml 的交互逻辑
    /// </summary>
    public partial class LoginPage : System.Windows.Controls.Page
    {
        public LoginPage()
        {
           
            InitializeComponent();
        }

        private void Login_Click(object sender, RoutedEventArgs e)
        {
            string account = Account.Text;
            string password = Pass.Password;
            BLL.User User = new BLL.User();
            if (account == "" || password == "")
            {
                ErrMsg.IsActive = false;
                NullMsg.IsActive = true;
                return;
            }
            UserInfo user = new UserInfo(account, password);
            switch (User.CheckPassword(account, password))
            {
                case -1:
                    {
                        NullMsg.IsActive = false;
                        ErrMsg.IsActive = true;
                        break;
                    }
                case 0:
                    Common.User = User.ShowUserInfo(account);//只要登录成功就获取用户全部数据
                    Account.Text = string.Empty;
                    Pass.Password = string.Empty;
                    MainWindow w1 = new MainWindow();
                    var window = Window.GetWindow(this);
                    window.Close();
                    w1.frame1.Source = new Uri("Page/ProductShowPage.xaml", UriKind.Relative);
                    w1.ShowDialog();
                    break;
                case 1:
                    Common.User = user;
                    Manager w = new Manager();
                    var win = Window.GetWindow(this);
                    win.Close();
                    w.ShowDialog();
                    break;
            }
        }

        private void save_Akg_Click(object sender, RoutedEventArgs e)
        {

            NullMsg.IsActive = false;
            ErrMsg.IsActive = false;
        }
    }
}
